import { request } from '@/service/request';

/**
 * 查询作业实例列表
 */
export function fetchOpsInstanceList(params?: Api.Dataplatform.OpsInstanceSearchParams) {
  return request<Api.Dataplatform.OpsInstanceList>({
    url: '/dataplatform/ops/instances',
    method: 'get',
    params
  });
}

/**
 * 查询作业实例详情
 */
export function fetchOpsInstanceDetail(instanceId: number) {
  return request<Api.Dataplatform.OpsInstanceDetail>({
    url: `/dataplatform/ops/instances/${instanceId}`,
    method: 'get'
  });
}

/**
 * 查询作业实例树形结构
 */
export function fetchOpsInstanceTree(instanceId: number) {
  return request<Api.Dataplatform.OpsInstanceTree>({
    url: `/dataplatform/ops/instances/${instanceId}/tree`,
    method: 'get'
  });
}

/**
 * 获取实例日志
 */
export function fetchOpsInstanceLogs(instanceId: number) {
  return request<string>({
    url: `/dataplatform/ops/instances/${instanceId}/logs`,
    method: 'get'
  });
}

/**
 * 下载实例日志
 */
export function downloadOpsInstanceLogs(instanceId: number) {
  return `/dataplatform/ops/instances/${instanceId}/logs/download`;
}

/**
 * 重跑作业实例
 */
export function rerunOpsInstance(instanceId: number) {
  return request<number>({
    url: `/dataplatform/ops/instances/${instanceId}/rerun`,
    method: 'post'
  });
}

/**
 * 停止作业实例
 */
export function stopOpsInstance(instanceId: number) {
  return request({
    url: `/dataplatform/ops/instances/${instanceId}/stop`,
    method: 'post'
  });
}

/**
 * 批量停止作业实例
 */
export function batchStopOpsInstances(instanceIds: number[]) {
  return request<number>({
    url: '/dataplatform/ops/instances/batch-stop',
    method: 'post',
    data: instanceIds
  });
}

/**
 * 批量重跑作业实例
 */
export function batchRerunOpsInstances(instanceIds: number[]) {
  return request<number>({
    url: '/dataplatform/ops/instances/batch-rerun',
    method: 'post',
    data: instanceIds
  });
}

/**
 * 删除作业实例
 */
export function deleteOpsInstance(instanceId: number) {
  return request({
    url: `/dataplatform/ops/instances/${instanceId}`,
    method: 'delete'
  });
}

/**
 * 批量删除作业实例
 */
export function batchDeleteOpsInstances(instanceIds: number[]) {
  return request<number>({
    url: '/dataplatform/ops/instances',
    method: 'delete',
    data: instanceIds
  });
}
